limsPerson.editPage = {

    getGridParam: function () {
        let _this = this;
        return {
            type: 'grid',
            id: 'lims-person-edit-list-grid',
            url: limsPerson.baseUrl + '/queries',
            service: 'limsPersonServiceImpl',
            dbTable: 'T_LIMS_PERSON',
            columns: limsPerson.getEditListColumns(),
            onCellClick: function (field, row) {
                field === 'personName' && _this.loadDetailPage(row);
            },
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0)
                }
            },
            deleteFormatter: function (row) {
                return row.personName || row.id
            },
            onRowActive: function (index, row) {
            },
            page: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.INSERT',
                icon: 'add',
                onClick: function () {
                    var model = Gikam.create('modal', {
                        title: 'BASEMODULE.RM.PERSONS.MODAL.ADD',
                        height: '250',
                        width: '400',
                    })
                    Gikam.create('layout', {
                        renderTo: model.window.$dom,
                        center: {
                            items: [{
                                type: 'form',
                                id: 'insert-person-form',
                                titleWidth: 80,
                                fields: limsPerson.getPersonInsertFormFields(),
                                columns: 1,
                                onLoadSuccess: function () {
                                }
                            }, {
                                type: 'btnToolbar',
                                items: [{
                                    type: 'button',
                                    text: 'GIKAM.BUTTON.CONFIRM',
                                    class: 'blue',
                                    icon: 'save',
                                    color: 'white',
                                    onClick: function () {
                                        var form = Gikam.getComp('insert-person-form');
                                        if (form.validate()) {
                                            var data = Gikam.getComp('insert-person-form').getData();
                                            var url = limsPerson.baseUrl;
                                            Gikam.postText(url, Gikam.getJsonWrapper(null, [null, [data]])).done(function (id) {
                                                Gikam.getLastModal().close(data);
                                                _this.loadDetailPage(id);
                                            });

                                        }
                                    }
                                }, {
                                    type: 'button',
                                    text: 'GIKAM.BUTTON.CANCEL',
                                    icon: 'back',
                                    onClick: function () {
                                        Gikam.getLastModal().close()
                                    }
                                }]
                            }]
                        }
                    })
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick: function () {
                    Gikam.getComp('lims-person-edit-list-grid').deleteRows(limsPerson.baseUrl)
                }
            }]
        }
    },

    loadDetailPage: function (row) {
        workspace.window.load(limsPerson.baseUrl + '/page/page/detail' + Gikam.param({
            id: row.id,
            personName: row.personName
        }));
    },

    create: function () {
        let _this = this;
        Gikam.create('layout', {
            id: 'lims-person-edit-list-layout',
            renderTo: workspace.window.$dom,
            center: {
                items: [this.getGridParam()]
            }
        })
    },

    init: function () {
        this.create()
    }
}
